<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import goodsSpecValue from '@/api/goods/goodsSpecValue'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  goodsSpecValue.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  goodsSpecValue.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'goods_spec_value',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: goodsSpecValue.getList,
  recycleApi: goodsSpecValue.getRecycleList,
  add: {
    show: true,
    api: goodsSpecValue.save,
    auth: ['goods:specValue:save']
  },
  edit: {
    show: true,
    api: goodsSpecValue.update,
    auth: ['goods:specValue:update']
  },
  delete: {
    show: true,
    api: goodsSpecValue.deletes,
    auth: ['goods:specValue:delete'],
    realApi: goodsSpecValue.realDeletes,
    realAuth: ['goods:specValue:realDeletes']
  },
  recovery: {
    show: true,
    api: goodsSpecValue.recoverys,
    auth: ['goods:specValue:recovery']
  },
  import: {
    show: true,
    url: 'goods/specValue/import',
    templateUrl: 'goods/specValue/downloadTemplate',
    auth: ['goods:specValue:import']
  },
  export: {
    show: true,
    url: 'goods/specValue/export',
    auth: ['goods:specValue:export']
  }
})

const columns = reactive([
  {
    title: "规格值ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入规格值ID"
    }
  },
  {
    title: "规格值",
    dataIndex: "spec_value",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入规格值"
    }
  },
  {
    title: "规格组ID",
    dataIndex: "spec_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入规格组ID"
    }
  },
  {
    title: "商城ID",
    dataIndex: "store_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入商城ID"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'goods:specValue' } </script>